jQuery(function($){
    var swiper = new Swiper('.sw1', {
        pagination: '.swiper-pagination',
        paginationClickable: '.swiper-pagination',
        spaceBetween: 30,
        autoplay: 1000
    });
    var swiper = new Swiper('.sw2', {
        pagination: '.swiper-pagination',
        slidesPerView: 2.3,
        paginationClickable: true,
        spaceBetween: 20,
        freeMode: true
    });
    var swiper = new Swiper('.sw3', {
        pagination: '.swiper-pagination',
        slidesPerView: 2.3,
        paginationClickable: true,
        spaceBetween: 20,
        freeMode: true
    });
    var swiper1 = new Swiper('.nav-list', {
        slidesPerView:2,//显示数量
        freeMode : true,
        freeModeMomentumRatio: 0.5
    });
    swiper1.container.on("click", function(){

        var slide = swiper1.slides.eq(swiper1.clickedIndex);
        
        slide.addClass("active").siblings().removeClass("active");

        var swiperHalf = swiper1.width / 2;
        var maxTranslate = swiper1.maxTranslate();
        var maxWidth = -maxTranslate + swiperHalf;

        var slideLeft = slide[0].offsetLeft;
        var slideWidth = slide[0].clientWidth;
        var slideCenter = slideLeft + slideWidth / 2;
        // 被点击slide的中心点

        swiper1.setWrapperTransition(300);

        if (slideCenter < swiperHalf) {
            swiper1.setWrapperTranslate(0);
        } else if (slideCenter > maxWidth) {
            swiper1.setWrapperTranslate(maxTranslate);
        } else {
            var translate = slideCenter - swiperHalf;
            swiper1.setWrapperTranslate(-translate);
        }
        
        swiper2.slideTo(swiper1.clickedIndex);
    })
    
    var swiper2 = new Swiper('.sw', {
        onSlideChangeStart: function(swiper){
            swiper1.clickedIndex = swiper.activeIndex;
            swiper1.slides.eq(swiper.activeIndex).trigger('click');
        }
    });

    $.ajax({
        type:'GET',
        url:'../json/index.json',
        dataType:'json',
        success:function(data){
            var str=template('moban',{arr:data});
            $('.yous').html(str);
        }
    });

    // $('.aa').click(function(){
    //     $(this).css("background","#ccc");
    //     location.href="html/faxian.html";
    // });
});
